<?php
class AuthController extends BaseController
{
    public function actionLogin()
    {
        // new user
        $userId = FacebookUtility::getUserId();
        $user = UserUtility::getById($userId);
        if(!$user)
        {
            $user = UserUtility::add($userId);
        }

        // daily
        if(substr($user->last_login, 0, 10) < date('Y-m-d'))
        {
            UserUtility::daily($userId);
        }

        // login
        UserUtility::login($userId);
        
        // redirect
        $this->redirect((array)CONST_LOGIN_REDIRECT);
    }
    
    public function actionLogout()
    {
        FacebookUtility::destroySession();
        $this->redirect((array)CONST_LOGIN_PAGE);
    }
}